package com.wg.wuge.tulin.jmm;

import java.util.concurrent.locks.ReentrantLock;

public class CountdownLatchTest {
    private int count;

    public static void main(String[] args) throws InterruptedException {
        CountdownLatchTest test = new CountdownLatchTest();
        test.sum();
    }

    public void sum() {
        ReentrantLock reentrantLock = new ReentrantLock();
        for (int index = 0; index < 5; index++) {
            int finalIndex = index;
            new Thread(() -> {
                reentrantLock.lock();
                try {
                    count++;
                    System.out.println(Thread.currentThread().getName() + " index : " + finalIndex);
                } finally {
                    reentrantLock.unlock();
                }
            }).start();
        }
        System.out.println(count);
    }
}
